package containers
{
	/*
	**********************************************************************************
	OFFICEMAX INCORPORATED
	Copyright (c) 2010 OfficeMax
	************************************************************************************
	All Rights Reserved.
	NOTICE: OfficeMax permits you to use, modify, and distribute this file in
	accordance with the terms of the license agreement accompanying it.
	
	************************************************************************************
	Author                 		Date           		 Description of change
	(Enter the author			(Enter the date        (What kind of change is done
	name who made the     		when the file is        in the file)
	change or created the file)  created/updated)
	***********************************************************************************
	*/
	

	import flash.events.Event;
	import flash.events.MouseEvent;
	import mx.binding.utils.BindingUtils;
	import mx.controls.Alert;
	import mx.core.FlexGlobals;
	import mx.events.FlexEvent;
	import spark.components.Button;
	import spark.components.Panel;
	
	
	[Event(type = "stateChange", source = "flash.events.Event")]
	[SkinState("collapsed")]
	[SkinState("collapsedWithControlBar")]
	[SkinPart("title")]
	public class NonCollapsiblePanel extends Panel
	{
		protected var _collapsed:Boolean;
		
		[SkinPart(required = "false")]
		public var collapseButton:CollapsiblePanelHeaderButton;
		
		
		/**
		 * Gives Collapsed\Not Collapsed status of the panel.
		 *
		 * @return boolean value which tells whether the panel is collapsed or not.
		 *
		 */
		public function get collapsed():Boolean
		{
			return _collapsed;
		}
		
		/**
		 * @private
		 */
		public function set collapsed(value:Boolean):void
		{
			_collapsed = value;
			if (collapseButton)
				collapseButton.collapsed = value;
			invalidateSkinState();
		}
		
		/**
		 * @private
		 */
		override protected function getCurrentSkinState():String
		{
			return collapsed ? "collapsed" : super.getCurrentSkinState();
		}
		
		/**
		 * Changes the state of the panel to collapsed\not-collapsed
		 * on click of the collapse button.
		 *
		 */
		protected function collapseButtonClickHandler(event:MouseEvent):void
		{
			
			collapsed = !collapsed;
			collapseButton.collapsed = collapsed;
			this.dispatchEvent(new Event("stateChange", true));
			
		}
		
		/**
		 * @private
		 */
		override protected function partAdded(partName:String, instance:Object):void
		{
			super.partAdded(partName, instance);
			
			if (instance == collapseButton)
			{
				Button(instance).addEventListener(MouseEvent.CLICK, collapseButtonClickHandler);
			}
		}
		
		/**
		 * @private
		 */
		override protected function partRemoved(partName:String, instance:Object):void
		{
			if (instance == collapseButton)
			{
				Button(instance).removeEventListener(MouseEvent.CLICK, collapseButtonClickHandler);
			}
			super.partRemoved(partName, instance);
		}
	}
}
